﻿using Alchemy.Classes;
using Newtonsoft.Json;
using Rebazza.Server.Interfaces;

namespace Rebazza.Server.Entities
{
    public class BaseUser : IBaseUser
    {
        public long Id { get; set; }

        public string Login { get; set; }

        public bool IsAuthorized { get; set; }

        public UserContext Context { get; set; }

        public BaseUser()
        {
        }

        public BaseUser(UserContext context)
        {
            Context = context;
            // TODO: delete this after authentication will implemented
            Login = Context.ClientAddress.ToString();
        }

        public void Send(Message message)
        {
            Context.Send(JsonConvert.SerializeObject(message));
        }

        public override bool Equals(object obj)
        {
            return Login.Equals(obj as string);
        }

        public override int GetHashCode()
        {
            return (int)Id ^ Login.GetHashCode();
        }
    }
}
